<template>
	<div class="components-container">
        <div class="header-form">
           <div class="layui-inline">
                <label   class="layui-form-label" >部门名称 </label>
              <div class="layui-input-inline">
                <el-input v-model="selectData.nameLike" placeholder="请输入部门名称"  ></el-input>
              </div>
            </div>
          <div class="layui-inline">
                <label  class="layui-form-label" >部门编号 </label>
              <div class="layui-input-inline">
                <el-input v-model="selectData.noLike" placeholder="请输入部门编号"></el-input>
                </div>
            </div>
          <div class="layui-inline">
              <label  class="layui-form-label" >联系电话 </label>
              <div class="layui-input-inline">
              <el-input v-model="selectData.telLike" placeholder="请输入联系电话" ></el-input>
              </div>
          </div>
          <div class="layui-inline">
                <label  class="layui-form-label">联系人</label>
                <div class="layui-input-inline">
                <el-input v-model="selectData.psnLike" placeholder="请输入联系人" ></el-input>
                </div>
            </div>
           <div class="layui-inline">
                <label class="layui-form-label">部门状态 </label>
                <div class="layui-input-inline">
                <el-select v-model="selectData.StatusEquals" placeholder="全部">
                    <el-option label="全部" :value="null"></el-option>
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                </div>
            </div>

            <el-button type="primary"  @click="btnSearch" >搜索</el-button>
            <el-button @click="btnRepeat" >重置</el-button>
        </div>

         <div>
            <ul class="toolList">
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)" :key=index>
                    <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>
         <!--数据列表-->
        <dataTable :headList="headList" :dataList="list" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

        <!-- 修改 | 详情 | 新增 -->
      <department ref="depts" @refreshData="getData"></department>

      <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
	</div>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
<script>
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import staEndUse from "../basic/staEndUse";
import { manage } from "@/mixins/managePage.js";
import { ORDER } from "@/const/orderConst.js";
import department from "./departmentMain";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";

export default {
  name: "departmentManage",
  mixins: [manage],
  data() {
    return {
      //当前选中行
      currentRow: null,
      list: [],
      states: [],
      options: [],
    
      selectData: {},
      loading: false,
   
    };
  },
  methods: {
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case ADD:
          this.$refs.depts.open(this.order);
          break;
        case MODIFY:
        case DELETE:        
        case INFO:
          this.$refs.depts.open(this.order, this.currentRow.DPTID);
          break;
        case ORDER.START:
        case ORDER.END:
          this.$refs.useMain.open(this.order, this.currentRow.DPTID);
          break;
        default:
      }
    },
  
    //获取列项
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetDeptColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },

    getData() {
      //部门查询
      let Data = JSON.parse(JSON.stringify(this.selectData));
      var data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(data, apiBase.getApiAdress().Dept.Query, res => {
        this.list = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
      });
    },
    getByNormal() {
      //查询正常状态部门信息
      var data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Dept.GetDeptStatus,
        res => {
          this.states = res.data.content;
          let results = res.data.content,
            legends = results.map(item => ({
              value: item.Value,
              label: item.Text
            }));
          this.options = legends;
        }
      );
    },
   
      //获取当前选中行
    selectRow(row, order) {
      this.currentRow = row;
      // console.log('currentRow',this.currentRow)
      if (order !== "") {
        this.operate(order);
      }
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        status = this.currentRow.DPTSTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case INFO:
        case MODIFY:
        case DELETE:
          return status !== '';
          break;
        case ORDER.END:
          return status === 'A';
          break;
        case ORDER.START:
          return status === 'B';
        default:
      }
    },
    btnSearch() {
      this.getData();
    },
    btnRepeat() {
      this.selectData = {};
      this.getData();
    }
  },

  mounted() { },
  components: {
    department,
    staEndUse,
    dataTable
  },
  created() {
    this.getColumns();
     this.getData();
     this.getByNormal();
  }
};
</script>